/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.merak.core.web;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.merak.core.Application;
import org.merak.core.Initializer;

//@WebServletContextListener
public class ContextLoaderListener implements ServletContextListener  {

	//~ Methods //////////////////////////////////////////////////////////////////
	//****************************************************************************
	@Override
	public void contextInitialized(ServletContextEvent event) {

		// Get Servlet context information
		ServletContext context = event.getServletContext();

		// Based on Context Info, initialize Merak Core API
		Initializer.setDocBase ( context.getRealPath("") );
		Initializer.setIsWebApp( true );

	}
	//****************************************************************************
	@Override
	public void contextDestroyed(ServletContextEvent event) {

		// Safe finish application
		Application.getLogger().info("UNDEPLOY received. Shutting down NOW!");
		Application.shutdown();

	}
	//****************************************************************************


}
